<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>岗位</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../../static/css/style.css"  media="all">
    <script type="text/javascript" src="../../static/js/jquery.min.js" ></script>
    <script src="../../layui/layui.all.js" charset="utf-8"></script>
    <script src="../../static/js/base.js" charset="utf-8"></script>
    <script src="../../static/js/ax.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body class="bg_w">
<div class="layui-fluid">
    <div class="content-wrap">

        <form class="layui-form layui-form-pane" id="from1">
            <input type="hidden" name="id" value="${merchant.id}" />
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <label class="layui-form-label" >岗位代码<span
                            class="red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="code" value="" class="layui-input code"
                               lay-verify="required|username" placeholder="岗位代码字母+数字，50字符内">
                    </div>
                </div>
                <div class=" layui-col-md6">
                    <label class="layui-form-label" >岗位名称<span
                            class="red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="name" value="" class="layui-input"
                               lay-verify="required|name" placeholder="岗位名称汉字+字母+数字，50字符内">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" >岗位描述<span
                            class="red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="remarks" lay-verify="required|remarks" value="" class="layui-input"
                               placeholder="岗位描述汉字+字母+数字，500字符内">
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space15">
                <div class="layui-col-xs6">
                    <label class="layui-form-label">总校<span class="red">*</span></label>
                    <div class="layui-input-block">
                        <input type="hidden" name="depCode"  id="depCode"/>
                        <input type="text" disabled="disabled" name="depName" id="depName" class="layui-input"  lay-verify="required" placeholder="请选择总校">
                    </div>
                </div>
                <div class="layui-col-xs6">
                        <button type="button" onclick="depj()" class="layui-btn add_btn">总&nbsp;&nbsp;&nbsp;&nbsp;校</button>
                </div>
            </div>

            <div class="layui-row layui-col-space15">
                <div class="layui-col-xs6">
                    <label class="layui-form-label">分校<span class="red"></span></label>
                    <div class="layui-input-block">
                        <input type="hidden" name="depCodeF"  id="depCodeF"/>
                        <input type="text" disabled="disabled" name="depNameF" id="depNameF" class="layui-input"   placeholder="请选择分校">
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <button type="button" onclick="depf()" class="layui-btn add_btn">分&nbsp;&nbsp;&nbsp;&nbsp;校</button>
                </div>
            </div>

            <div class="layui-row layui-col-space15">
                <div class="layui-col-xs6">
                    <label class="layui-form-label">报名点<span class="red"></span></label>
                    <div class="layui-input-block">
                        <input type="hidden" name="depCodeB"  id="depCodeB"/>
                        <input type="text" disabled="disabled" name="depNameB" id="depNameB" class="layui-input" placeholder="请选择报名点">
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <button type="button" onclick="depb()" class="layui-btn add_btn">报名点</button>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn add_btn btn-left" lay-submit="" lay-filter="addNews">提交</button>
                    <!--<button type="reset" class="layui-btn layui-btn-primary">关闭</button>-->
                </div>
            </div>
        </form>

    </div>
</div>

<script>
    function depj() {
        layui.layer.open({
            id:'',
            title : "总校列表",
            type : 2,
            area: ['800px', '400px'],
            btn: ['确定','取消'],
            content : "departmentList.html?depType=J",
            yes: function (index,layero) {
                var departmentCode = layero.find("iframe")[0].contentWindow.$("#departmentCode").val();
                var departmentName = layero.find("iframe")[0].contentWindow.$("#departmentName").val();
                if(departmentCode==null || departmentCode==""){
                    layer.msg("请选择总校");
                }else{
                    $("#depCode").val(departmentCode);
                    $("#depName").val(departmentName);

                    $("#depCodeF").val("");
                    $("#depNameF").val("");
                    $("#depCodeB").val("");
                    $("#depNameB").val("");
                    layer.close(index);
                }
            } ,
            btn2: function (index,layero) {
                layer.close(index);
            }
        });
    }

    function depf() {
        layui.layer.open({
            id:'',
            title : "分校列表",
            type : 2,
            area: ['800px', '400px'],
            btn: ['确定','取消'],
            content : "departmentList.html?depType=F&parentCode="+  $("#depCode").val(),
            yes: function (index,layero) {
                var departmentCode = layero.find("iframe")[0].contentWindow.$("#departmentCode").val();
                var departmentName = layero.find("iframe")[0].contentWindow.$("#departmentName").val();
                if(departmentCode==null || departmentCode==""){
                    layer.msg("请选择分校");
                }else{
                    $("#depCodeF").val(departmentCode);
                    $("#depNameF").val(departmentName);

                    $("#depCodeB").val("");
                    $("#depNameB").val("");
                    layer.close(index);
                }
            } ,
            btn2: function (index,layero) {
                layer.close(index);
            }
        });
    }

    function depb() {
        layui.layer.open({
            id:'',
            title : "报名点列表",
            type : 2,
            area: ['800px', '400px'],
            btn: ['确定','取消'],
            content : "departmentList.html?depType=B&parentCode="+  $("#depCodeB").val(),
            yes: function (index,layero) {
                var departmentCode = layero.find("iframe")[0].contentWindow.$("#departmentCode").val();
                var departmentName = layero.find("iframe")[0].contentWindow.$("#departmentName").val();
                if(departmentCode==null || departmentCode==""){
                    layer.msg("请报名点总校");
                }else{
                    $("#depCodeB").val(departmentCode);
                    $("#depNameB").val(departmentName);
                    layer.close(index);
                }
            } ,
            btn2: function (index,layero) {
                layer.close(index);
            }
        });
    }
    function position() {
        var departmentCode=$("#depCode").val();
        if(departmentCode==null || departmentCode==""){
            layer.msg("请先选择部门");
            return false;
        }
        layui.layer.open({
            id:'',
            title : "岗位列表",
            type : 2,
            area: ['850px', '350px'],
            btn: ['确定','取消'],
            content :backendWebUrl+ "positionList.html?departmentCode="+$("#depCode").val(),
            yes: function (index,layero) {
                var positionId = layero.find("iframe")[0].contentWindow.$("#positionId").val();
                var positionName = layero.find("iframe")[0].contentWindow.$("#positionName").val();
                if(positionId==null || positionId==""){
                    layer.msg("请选择岗位");
                }else{
                    $("#positionId").val(positionId);
                    $("#positionName").val(positionName);
                    layer.close(index);
                }
            } ,
            btn2: function () {
                layer.close(index);
            }
        });
    }
    layui.config({
        base: "js/"
    }).use(['form', 'layer', 'jquery', 'layedit', 'laydate', 'upload'], function (){
        var form = layui.form;
        var layer = parent.layer === undefined ? layui.layer : parent.layer;
        var laypage = layui.laypage;
        var layedit = layui.layedit;
        var laydate = layui.laydate;
        var $ = layui.jquery;

        //添加验证规则
        form.verify({
            username:[
                /^[a-zA-Z][a-zA-Z0-9]{1,50}$/,
                "岗位代码必须是字母+数字，50字符内！"
            ],
            name:[
                /^[a-zA-Z0-9\u4e00-\u9fa5]{1,50}$/,
                '岗位名称只能输入汉字、字母和数字，50字符内'
            ],
            remarks:function (value, item) {
                if(value.length>500){
                    return '岗位描述不能超过500字符'
                }
            }
        });

        form.on("submit(addNews)", function (data) {
            ax.post({
                type: "post",
                url: backendWebUrl+"/api/school/position/addPosition",
                data: $("#from1").serialize(),
                contentType: "application/x-www-form-urlencoded",
                success: function (data) {
                    layer.msg(data.message);
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }
            });
            return false;
        });
    })
</script>
</body>
</html>